<template>
  <div class="content">
    <HearderTop></HearderTop>
    <searchBox :backColor="backColor"></searchBox>
    <div ref="contentRef" class="home_content" @scroll="scrollContent">
      <el-backtop :right="50" :bottom="70" target=".home_content" style="background: none">
        <img src="@/assets/images/back_top.png" style="width: 140px; height: 140px" />
      </el-backtop>
      <div class="content_banner mb20">
        <el-carousel height="28vw" autoplay arrow="never">
          <el-carousel-item v-for="item in bannerList" :key="item">
            <img :src="item.img" style="width: 100%; height: 100%" />
          </el-carousel-item>
        </el-carousel>
      </div>
      <div class="content_tips mb10">
        <div class="tip_box" v-for="item in tipList" :key="item.iconId">
          <div class="tip_circle mr10">
            <img :src="item.icon" />
          </div>
          <div class="tip_content">
            <div class="content_title mb10">{{ item.title }}</div>
            <div class="content_text">{{ item.content }}</div>
          </div>
        </div>
      </div>
      <div class="content_category">
        <div class="mb10" v-for="category in categoryList" :key="category.categoryId">
          <div class="category_title mb10 mt20">
            <div class="title_text">
              {{ category.name }}
              <span v-if="category.remark">({{ category.remark }})</span>
            </div>
            <div class="title_operate" @click="handelCheckMore(category)">
              查看更多
              <el-icon>
                <arrow-right-bold />
              </el-icon>
            </div>
          </div>
          <div class="category_product">
            <div
              class="product_card"
              v-for="product in category.productList"
              :key="product.productId"
              @click="handelCheckDetails(product, category)"
            >
              <img class="card_img" :src="product.mainPicUrl" />
              <div class="card_title">{{ product.productAliasName }}</div>
              <div class="card_price">¥{{ product.businessLowestPrice }}</div>
            </div>
          </div>
        </div>
      </div>
      <div class="bottoms">我是有底线哒~</div>
    </div>
  </div>
</template>
<script setup>
import { getBanners, getCategoryProductList, gettenant } from "@/apis/shopHome/home";
import { useRouter } from "vue-router";
import HearderTop from "@/views/home/components/HearderTop";
import searchBox from "@/views/home/components/search";
import { ref } from "vue";
import shopSelectStore from "@/store/modules/shopSelect";

const router = useRouter();
const contentRef = ref();
const backColor = ref(true);
const bannerList = ref([]);
const tipList = ref([]);
const categoryList = ref([]);
const shopSelect = shopSelectStore();

const getBannerList = async () => {
  const { data } = await getBanners(0);
  bannerList.value = data;
};

const getTipList = async () => {
  const { data } = await gettenant();
  tipList.value = data || [];
};

const scrollContent = ({ target }) => {
  backColor.value = !(target.scrollTop > 0);
};

const getCategoryListFn = async () => {
  const { data } = await getCategoryProductList();
  categoryList.value = data || [];
};

const handelCheckMore = item => {
  shopSelect.setShopSelect(item);

  const routeUrl = router.resolve({
    path: "/shopCategories/index",
    query: {
      categoryId: item.categoryId
    }
  });
  window.open(routeUrl.href, "_blank");
};

const handelCheckDetails = (items, item) => {
  shopSelect.setShopSelect(item);
  shopSelect.setShopDetail(items);
  const routeUrl = router.resolve({
    path: "/shopDetail/index",
    query: {
      id: items.productId
    }
  });
  window.open(routeUrl.href, "_blank");
};

(() => {
  getBannerList();
  getTipList();
  getCategoryListFn();
})();
</script>
<style lang="scss">
#designer-app {
  overflow: auto !important;
}
.content {
  box-sizing: border-box;
  padding-top: 114px;
  height: 100%;
  .home_content {
    box-sizing: border-box;
    padding: 8px 14px 14px 20px;
    height: 100%;
    overflow-x: hidden;
    overflow: auto;
    .content_banner {
      border-radius: 10px;
      overflow: hidden;
      box-shadow: 4px 5px 16px 0px rgba(4, 19, 74, 0.04);
    }
    .content_tips {
      display: flex;
      justify-content: space-between;
      padding: 20px;
      background: #dbe2e8;
      box-shadow: 4px 5px 16px 0px rgba(4, 19, 74, 0.04);
      border-radius: 10px 10px 0px 0px;
      .tip_box {
        display: flex;
        align-items: center;
        .tip_circle {
          display: flex;
          align-items: center;
          justify-content: center;
          width: 56px;
          height: 56px;
          background-color: #e8eef6;
          box-shadow:
            inset 4px 6px 4px 0 rgba(4, 24, 48, 0.3),
            inset -1px -1px 1px 0px #ffffff;
          border-radius: 32px;
          img {
            width: 32px;
            height: 32px;
            border-radius: 50%;
          }
        }
        .tip_content {
          .content_title {
            color: rgba(4, 24, 48, 0.6);
            line-height: 20px;
          }
          .content_text {
            font-size: 12px;
            color: rgba(78, 89, 105, 0.6);
            line-height: 17px;
          }
        }
      }
    }
    .content_category {
      .category_title {
        display: flex;
        justify-content: space-between;
        align-items: center;
        .title_text {
          font-size: 16px;
          color: #4e5969;
          line-height: 36px;
        }
        .title_operate {
          display: flex;
          align-items: center;
          cursor: pointer;
          gap: 5px;
        }
      }
      .category_product {
        display: grid;
        grid-template-columns: repeat(auto-fill, minmax(289px, 1fr));
        grid-template-rows: 400px 0 0 0;
        justify-content: center;
        gap: 0 20px;
        .product_card {
          position: relative;
          top: 0;
          overflow: hidden;
          text-align: center;
          background: #ffffff;
          box-shadow: 4px 5px 16px 0px rgba(4, 19, 74, 0.04);
          border-radius: 10px 10px 10px 10px;
          transition: all 0.1s ease-in-out;
          .card_img {
            width: 100%;
            height: 280px;
            border-radius: 10px;
          }
          .card_title {
            box-sizing: border-box;
            padding: 0 20px;
            margin-top: 26px;
            font-weight: 700;
            font-size: 16px;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
            color: #3d3d3d;
            line-height: 24px;
          }
          .card_price {
            font-family: din;
            margin-top: 10px;
            height: 24px;
            font-weight: 700;
            font-size: 16px;
            color: #4e5969;
            line-height: 24px;
          }
        }
        .product_card:hover {
          top: -10px;
          box-shadow: 4px 8px 16px 0px rgba(4, 54, 114, 0.15);
        }
      }
    }
  }
  .bottoms {
    display: flex;
    justify-content: center;
    font-weight: 700;
    font-size: 14px;
    color: rgba(61, 61, 61, 0.3);
    line-height: 18px;
    padding: 50px 0 33px 0;
  }
}
</style>
